<?php

namespace app\common\model;

use think\Db;
use think\Model;

class Base extends Model
{

    protected $is_show = '1';
    protected $table = '';


    protected function getParents($arr, $current, $id_key = 'id', $parent_id_key = 'parent_id', $flag = false)
    {
        static $temp = array();
        if ($flag) {
            $temp = array();
        }
        foreach ($arr as $key => $value) {
            if ($value[$id_key] == $current[$parent_id_key]) {
                $temp[] = $value;
                $this->getParents($arr, $value, $id_key, $parent_id_key, false);
            }
        }

        return $temp;
    }
    public static function BaseOne($where)
    {
        return self::where($where)->find();
    }

    public static function BaseAll($where, $field="", $order = null)
    {
        if ($field) {
            $rst = self::where($where)->order($field, $order)->select();
        } else {
            $rst = self::where($where)->select();
        }
        return json_decode($rst, true);
    }
    //基础增加类
    public function BaseAdd($addData)
    {
        return $this->data($addData)->save();
    }
    //基础更新类
    public function BaseUpdate($where, $data)
    {
        $rst = $this->where($where)->update($data);
        return $rst;
    }
    //基础更新类
    public function BaseSetInc($where, $field,$step=1)
    {
        $rst = $this->where($where)->setInc($field, $step);
        return $rst;
    }
}
